import time
import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
import ddt

dp1 = [

    ('rose', 123456),
    ('jojo', 123456),
    ('hanamaki', 123456),
    ('andy', 123456),
]


@ddt.ddt()
class TestLogins(unittest.TestCase):
    driver = None

    @classmethod
    def setUpClass(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)

    @ddt.data(*dp1)
    def test_logins(self, info):
        self.driver.get("http://192.168.0.133/ecshop/index.php")
        self.driver.maximize_window()
        self.driver.find_element(By.CSS_SELECTOR, "#ECS_MEMBERZONE > a:nth-child(2) > img").click()
        self.driver.find_element(By.NAME, "username").send_keys(info[0])
        self.driver.find_element(By.NAME, "password").send_keys(info[1])
        self.driver.find_element(By.NAME, "submit").click()

        # 添加 断言 判断 登录 是否成功
        self.assertTrue(self.driver.page_source.__contains__('退出'))

        self.driver.find_element(By.CSS_SELECTOR, ".userInfo").click()
        self.driver.find_element(By.LINK_TEXT, "退出").click()

    @classmethod
    def tearDownClass(self):
        self.driver.quit()
        pass


if __name__ == '__main__':
    unittest.main()
